# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=addrwatch
pkgver=1.0.2
pkgrel=1
pkgdesc="IPv4/IPv6 and ethernet address pairing monitoring"
url="https://github.com/fln/addrwatch"
arch="all"
license="GPL-3.0-only"
makedepends="
	argp-standalone
	autoconf
	automake
	libevent-dev
	libpcap-dev
	mariadb-connector-c-dev
	sqlite-dev
	"
pkgusers="addrwatch"
pkggroups="addrwatch"
install="$pkgname.pre-install"
subpackages="
	$pkgname-mysql
	$pkgname-doc
	$pkgname-openrc
	"
source="https://github.com/fln/addrwatch/archive/v$pkgver/addrwatch-$pkgver.tar.gz
	use-HOST_NAME_MAX-macro.patch
	more-specific-library-linking.patch
	$pkgname.initd
	$pkgname.confd
	$pkgname-syslog.initd
	$pkgname-syslog.confd
	$pkgname-mysql.initd
	$pkgname-mysql.confd
	$pkgname.logrotated
	"
options="!check"  # no tests provided

prepare() {
	default_prepare
	./bootstrap.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-mysql \
		--enable-sqlite3
	make
}

package() {
	make install DESTDIR="$pkgdir"

	local name; for name in "$pkgname" "$pkgname-mysql" "$pkgname-syslog"; do
		install -D -m755 "$srcdir"/$name.initd "$pkgdir"/etc/init.d/$name
		install -D -m644 "$srcdir"/$name.confd "$pkgdir"/etc/conf.d/$name
	done
	install -D -m644 "$srcdir"/$pkgname.logrotated "$pkgdir"/etc/logrotate.d/$pkgname

	install -d -m750 -o addrwatch -g addrwatch "$pkgdir"/var/lib/$pkgname
}

mysql() {
	pkgdesc="$pkgdesc - with MySQL output"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/addrwatch_mysql
	amove etc/init.d/addrwatch-mysql
	amove etc/conf.d/addrwatch-mysql
}

sha512sums="
b0b1f246aadc8512dc5d9b44a21f8add9775aa7329520e47caafa2beaa74f6cd1a08d79c119c52fecf86adf93210c17ab050a1e3f94b079b1724fbdf015986a9  addrwatch-1.0.2.tar.gz
e1901e5e4b247dd47d73b5aab11e606dec45de6786e4ffefb7cd20dc5dc2e21c718f9e2f9670157e7f402465a749a42d4d88152eac5130c20f3060753510518a  use-HOST_NAME_MAX-macro.patch
590baf828610fba24d321de86f93187069be0bf672cd64983a3af325792b3df6506b5b292dce1dce729aaed134fa1223f7e67b63bee3ced5be3791bdb3846731  more-specific-library-linking.patch
c980320b0790b604b4340ffb2f99e039863c8c3c7981fd82144472522aefecb347d8317f0c779953e76a007557dd3220c081d2094c085183ec624c3fce32f35e  addrwatch.initd
2d1054a1ea7567889c19bddf4649731a3d9816f7a5a30ebb26b4d3a8ec9d4c3966ed33162d44d7c2477c6240631f11a76f97846f3235f4aa95d139cc629e6456  addrwatch.confd
6ac24eb3483621a98dac5e9042b7fa2b6ed83008251eb117d703d755dec81a982065a22771cd4f6e3af2a2819b4db27ba87e73b2f7a4b39cc5c6a735d8b25493  addrwatch-syslog.initd
5c24627b5f8e3b61ec3d86708e7e810a1a1724b600077f112635191dd02b9a91690758b2c84cf85c3022eba3bdb3bb1d33bdaca20b7f47c8ad01f738b68ef391  addrwatch-syslog.confd
d3c85a3f6f81f52c2e1cb22bc0d20d4bb2450737bc9187d87019e9c975a6a0b40bef834ca18c297788a3d99ca3c85fbb5cb52caabe82d1194e61f1e0e4d974ef  addrwatch-mysql.initd
c7ae8b3abe4fe617d7fe573ff3bb3723d4b629486962752745a76ea93cc38882e6fc5f473aeab48c3c0417be09669234feb3e81b0c440b8bcea70fb319e35251  addrwatch-mysql.confd
6afaaf203e87791d6d3707a61125007fbcf223b9f70e877d2aec389d1ea2397517ae84092607e386ace67e8ef979a692a1fa8e371e847058d5c1a218896c93ba  addrwatch.logrotated
"
